﻿using Shop.Common;
using Shop.Implementation.Customer;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;

namespace Shop.Interface.SO
{
    public abstract class ISO
    {
        public static Dictionary<string, object> Switch(string[] switchNames)
        {
            if (switchNames.Length <= 1) { return Common.ReturnValue.ErrAction(); }
            string swithname = switchNames[2];

            #region 验证是否登录并获取idcus
            int idCus;
            NameValueCollection nv = System.Web.HttpContext.Current.Request.QueryString;
            NameValueCollection nvc = HttpContext.Current.Request.Form;
            string token = string.IsNullOrEmpty((nvc["token"]).GetVal_String()) ? nv["token"].GetVal_String() : (nvc["token"]).GetVal_String();

            bool bret = CustomerCommon.check_token(token, out idCus);
            if (!bret)
            {
                return CustomerCommon.NotLogin();
            }
            #endregion
            ISO so = new Implementation.SO.ISO_V1();

            if (swithname == "GetList")
            { return so.GetList(idCus); }
            #region 验证用户状态
            string errstr;
            if (!CustomerCommon.CheckCustomerStatus(idCus, out errstr))
            {
                return ReturnValue.Get(errstr, false);
            }
            #endregion

            if (!so.IsServiceTime())
            { return ReturnValue.Get("商城的营业时间为9点到23点。请在营业时间内下单，谢谢配合！", false); }

            switch (swithname)
            {
                case "Save":
                    return so.Save(idCus);
                case "getYH":
                    return so.GetPreferential(idCus);
                case "selectCoupon":
                    return so.SelectedCoupon(idCus);
                case "HlSoStatusLog":
                    return so.HlSoStatusLog();
                default:
                    return Common.ReturnValue.ErrAction();
            }

        }
        //获取订单列表
        public abstract Dictionary<string, object> GetList(int idcus);

        //获取订单列表
        public abstract Dictionary<string, object> Save(int idcus);
        public abstract Dictionary<string, object> GetPreferential(int idcus);
        public abstract Dictionary<string, object> SelectedCoupon(int idcus);

        public abstract bool IsServiceTime();

        public abstract Dictionary<string, object> HlSoStatusLog();

    }
}